package com.gallsoft.games.bennyadv;

import com.gallsoft.games.framework.gamedev2d.DynamicGameObject;
import com.gallsoft.games.framework.math.Vector2;

public class Enemy extends DynamicGameObject {
    
    public static final float ENEMY_WIDTH = 1.0f;
    public static final float ENEMY_HEIGHT = 1.0f;
    //public static final float ENEMY_VELOCITY = 3f;
    
    public enum EnemyType {
        FLY,
        SNAIL,
        CRAB,
        EGG,
        PINKSWEET,
        BLUESWEET,
        TOMATO
    }

    float stateTime = 0;
    EnemyType enemyType;
    
    private float minimumX = -999;
    private float minimumY = -999;
    private float maximumX = 999;
    private float maximumY = 999;
    
    
    public Enemy(float x, float y, float width, float height, Vector2 newVelocity, EnemyType type) {
        super(x, y, width, height);
        
        velocity.set(newVelocity);
        enemyType = type; 
    }

    public void setVelocity(Vector2 newVelocity) {
        velocity.set(newVelocity);
    }

    public void update(float deltaTime) {
        position.add(velocity.x * deltaTime, velocity.y * deltaTime);
        bounds.lowerLeft.set(position).sub(ENEMY_WIDTH / 2, ENEMY_HEIGHT / 2);
        
        // Move vertically
        if (position.y < minimumY) {
            position.y = minimumY;
            velocity.y = -velocity.y;
        }
        else if (position.y > maximumY) {
            position.y = maximumY;
            velocity.y = -velocity.y;
        }
        
        // Move horizontally
        if (position.x < minimumX) {
            position.x = minimumX;
            velocity.x = -velocity.x;
        }
        else if (position.x > maximumX) {
            position.x = maximumX;
            velocity.x = -velocity.x;
        }
        
        stateTime += deltaTime;
    }
    
    public void setHorizontalRange(float minx, float maxx) {
        minimumX = minx;
        maximumX = maxx;
     }
    
    public void setVerticalRange(float miny, float maxy) {
        minimumY = miny;
        maximumY = maxy;
    }
}
